home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / drag_line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  1.9 KB  |  80 lines

  1. /*
  2.  * drag_line.c : click and drag line drawing mode
  3.  *
  4.  */
  5.  
  6. #include "common.h"
  7. #include "ui.h"
  8. #include "llist.h"
  9. #include "display.h"
  10. #include "reg.h"
  11. #include "sm.h"
  12.  
  13. struct plist *mpt;        /* point which we are moving */
  14.  
  15. /*
  16.  * start_line() -- takes an (x,y) starting point for a line, and pushes a
  17.  * routine to drag the endpoint of the line on to the dispatch function
  18.  * stack.
  19.  */
  20.  
  21. start_line(x, y)
  22.     int       x, y;
  23. {
  24.     int       dragline_dispatch();
  25.  
  26.     if ((mpt = (struct plist *) malloc(sizeof(struct plist))) == NULL) {
  27.     perror("malloc");
  28.     exit(1);
  29.     }
  30.     /*
  31.      * claim the state so that we can intercept mouse events to achieve an
  32.      * interactive move
  33.      */
  34.     dp_push(dragline_dispatch);
  35.     /* fill mpt appropriately */
  36.     mpt->pt.x = x;
  37.     mpt->pt.y = y;
  38.     printf("moving point at (%d,%d)\n", x, y);
  39.     /* add this (x,y) as the position of the first point */
  40.     add_point(x, y);
  41.     add_point(x, y);
  42.     mpt = pfind(mpt->pt);
  43. }
  44.  
  45. int
  46. dragline_dispatch(token, arg)
  47.     int       token;        /* token as defined in sm.h */
  48.     caddr_t   arg;        /* pointer to an optional argument */
  49. {
  50.     struct plist *getcpl();
  51.  
  52.     if (token == IMG_BUT) {
  53.     if ((event_action((Event *) arg) == LOC_DRAG) &&
  54.         (event_is_down((Event *) arg))) {
  55.         /* move the points */
  56.         /* replace old cross */
  57.         ref_cb(img_win->d_xid, &mpt->cb);
  58.         /* and draw a new one */
  59.         mpt->pt.x = dtoi(event_x((Event *) arg));
  60.         mpt->pt.y = dtoi(event_y((Event *) arg));
  61. #ifdef DEBUG
  62.         printf("moving point at (%d,%d)\n", (int) mpt->pt.x, (int) mpt->pt.y);
  63. #endif
  64.         cbget(orig_ximg, &mpt->cb, mpt->pt);
  65.         XSetForeground(display, gc, standout);
  66.         draw_cb(img_win->d_xid, &mpt->cb);
  67.         pvreg_set(getcpl());
  68.         return 1;
  69.     } else {
  70.         if (event_is_up((Event *) arg)) {
  71. #ifdef DEBUG
  72.         printf("clearing move_dispatch() from the dispatch stack \n");
  73. #endif
  74.         dp_del(dragline_dispatch);
  75.         }
  76.     }
  77.     }
  78.     return dispatch_next(token, (char **)arg);
  79. }
  80.